/*
* name;
*/
class Utils {
    public static angle(x1: number, y1: number, x2: number, y2: number): number {
        var diff_x = Math.abs(x2 - x1),
            diff_y = Math.abs(y2 - y1);
        if (diff_y == 0 || diff_x > diff_y) {
            if (x1 > x2) {
                //左
                return Define.LEFT;
            }
            //右
            return Define.RIGHT;
        }
        if (diff_x == 0 || diff_x < diff_y) {
            if (y1 < y2) {
                //下
                return Define.DOWN;
            }
        }
        return Define.RIGHT;
    }
    /**
     * 
     * @param x1 计算两点距离
     * @param y1 
     * @param x2 
     * @param y2 
     */
    public static range(x1: number, y1: number, x2: number, y2: number): number {
        var xdiff = x2 - x1;            // 计算两个点的横坐标之差
        var ydiff = y2 - y1;            // 计算两个点的纵坐标之差
        return Math.pow((xdiff * xdiff + ydiff * ydiff), 0.5);
    }
    /**
     * 点转坐标
     * @param posNode 
     */
    public static calc_pos_xy(posNode: ANode, hight: number): MPos {
        let x = posNode.y;
        let y = posNode.x;
        // let pos = new MPos(640/10, 1136/13 - hight);
        //let pos = new MPos(x * 70 + 35, y * 90 + 70 - hight);
        // let pos = new MPos(x * 640/13 + 35, y * 1136/20 + 70 - hight);
        let pos = new MPos(x * 640/13 + 30, y * 1136/20 + 10  - hight);
        return pos;
    }
    /**
     * 判断是否在攻击距离内
     * @param distance 
     * @param x1 
     * @param y1 
     * @param x2 
     * @param y2 
     */
    public static isDistance(distance: number, x1: number, y1: number, x2: number, y2: number): boolean {
        distance = distance;
        let dx: number = Math.abs(x1 - x2) - 35;
        let dy: number = Math.abs(y1 - y2) - 35;
        let distancePos: number = Math.sqrt(dx * dx + dy * dy);
        //console.log("攻击点" + (distancePos <= distance) + ",distance:" + distance + ",x1:" + x1 + ",y1:" + y1 + ",x2:" + x2 + ",y2:" + y2);
        return distancePos <= distance;
    }
    /**
     * 随机一个数
     * @param lower 
     * @param upper 
     */
    public static nextNumber(lower: number, upper: number): number {
        if (lower == upper) {
            return lower;
        }
        let r = Math.random();
        return Math.floor((r * upper) + ((1 - r) * lower) + r);
    }

    /**  
     * 颜色
     */
    public static getColour(colour: number): string {
        switch (colour) {
            case 1:
                return Define.Color_Green;
            case 2:
                return Define.Color_Blue;
            case 3:
                return Define.Color_Purple;
            case 4:
                return Define.Color_Yellow;
        }
        return Define.Color_Yellow;
    }
}